const dbm = require('../config/dbModels');
const { aseEncode}=require('../core/crypto')
const { createJWT } = require('../core/jwt')
const { createCookie } = require('../core/do-cookie')


class RegistryDao {
    /**
     * 创建用户
     * @param ctx 浏览器发送的数据
     * @return jwtStr
     */
    static async createUser(ctx) {
       let data=ctx.request.body

        let psd = aseEncode(data.password)
        var arr_res = await dbm.User.findOrCreate({ where: { username: data.username }, defaults: { password: psd} })
        if (!arr_res[1]) {
            throw new global.errs.ParameterException('该用户名已存在')
        }
        let encode_id = aseEncode(arr_res[0].id+'')
        return encode_id
    }
}
module.exports = RegistryDao
